﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gma.QrCodeNet.Encoding;
namespace QRcode
{
    class Program
    {
        static void Main(string[] args)
        {



            //在控制台中输出二维码：
            Console.BackgroundColor = ConsoleColor.White;    //将背景改为白色
            Console.ForegroundColor = ConsoleColor.Black;    //将前景改为黑色
            Console.Write(@"Type some text to QR code: ");   //输入提示字符
            string sampleText = Console.ReadLine();          //读取字符串
            while( sampleText.Length == 0)
            {
                Console.WriteLine(@"输入不能为空！");          //如果输入为空提示用户
                sampleText = Console.ReadLine();               //继续读取

            }
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);  //新建QrEncoder对象
            QrCode qrCode = qrEncoder.Encode(sampleText);
            for (int j = 0; j < qrCode.Matrix.Width; j++)
            {
                for (int i = 0; i < qrCode.Matrix.Width; i++)
                {

                    char charToPrint = qrCode.Matrix[i, j] ? '█' : '　';         //根据qrCode二维数组的值生成二维码
                    Console.Write(charToPrint);
                }
                Console.WriteLine();
            }
            Console.WriteLine(@"Press any key to quit.");
            Console.ReadKey();
        }
    }
}
